import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  CreateDateColumn,
  UpdateDateColumn,
  Tree,
  TreeChildren,
  TreeParent,
} from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { AssetType } from '../dtos/asset.dto';

@Entity('assets')
@Tree('materialized-path')
export class AssetEntity {
  @ApiProperty({ description: 'ID', example: 1 })
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true, length: 64 })
  @ApiProperty({ description: '资源名称', example: 'name' })
  name: string;

  @Column({ type: 'enum', enum: AssetType })
  @ApiProperty({ description: '资源类型', example: '菜单' })
  type: AssetType;

  @Column({ length: 200, nullable: true })
  @ApiProperty({ description: '资源地址', example: '/admin/user-list' })
  url: string;

  @Column({ length: 255, nullable: true })
  @ApiProperty({ description: '资源描述', example: '资源描述' })
  description: string;

  @TreeChildren()
  children: AssetEntity[];

  @TreeParent()
  parent: AssetEntity;

  @ApiProperty({ description: '启用状态', example: 1 })
  @Column({ default: 1 }) //是否生效 0无效 1有效
  status: number;

  @ApiProperty({ description: '排序编号', example: 1 })
  @Column({ default: 100 }) //排序编号
  sort: number;

  @ApiProperty({ description: '创建时间', example: '2025-02-11 15:17:02' })
  @CreateDateColumn()
  createdAt: Date;

  @ApiProperty({ description: '更新时间', example: '2025-02-11 15:17:02' })
  @UpdateDateColumn()
  updatedAt: Date;
}
